package edu.gdkm.dao;

import edu.gdkm.pojo.Language;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LanguageDao {

    // 根据ID查询
    @Select("SELECT * FROM Languages WHERE language_id = #{languageId}")
    Language selectById(Integer languageId);

    // 根据简历ID查询
    @Select("SELECT * FROM Languages WHERE resume_id = #{resumeId}")
    List<Language> selectByResumeId(Integer resumeId);

    // 查询所有
    @Select("SELECT * FROM Languages")
    List<Language> selectAll();

    // 新增
    @Insert("INSERT INTO Languages(resume_id, name, proficiency) " +
            "VALUES(#{resumeId}, #{name}, #{proficiency})")
    @Options(useGeneratedKeys = true, keyProperty = "languageId")
    int insert(Language language);

    // 更新
    @Update("UPDATE Languages SET resume_id = #{resumeId}, name = #{name}, proficiency = #{proficiency} " +
            "WHERE language_id = #{languageId}")
    int update(Language language);

    // 删除
    @Delete("DELETE FROM Languages WHERE language_id = #{languageId}")
    int delete(Integer languageId);
    
    // 根据简历ID删除
    @Delete("DELETE FROM Languages WHERE resume_id = #{resumeId}")
    int deleteByResumeId(Integer resumeId);
}
    